package com.ewhome.apartment.mvp.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewhome.apartment.R;
import com.jess.arms.utils.ArmsUtils;
import com.yqritc.recyclerviewflexibledivider.VerticalDividerItemDecoration;

import java.util.ArrayList;
import java.util.List;

import static android.support.v7.widget.LinearLayoutManager.HORIZONTAL;

/**
 * author:zhangjing
 * 作用:
 * return:
 */

public class RecylerViewAdapter extends DelegateAdapter.Adapter<BaseViewHolder>{
    private Context mContext;
    private LayoutHelper mLayouthelper;
    public RecylerViewAdapter(Context mContext, LayoutHelper mLayouthelper) {
        this.mContext = mContext;
        this.mLayouthelper = mLayouthelper;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayouthelper;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.recyler,parent,false);
        return new BaseViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        RecyclerView recyclerView=holder.<RecyclerView>getView(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.addItemDecoration(new VerticalDividerItemDecoration.Builder(mContext)
                .color(Color.WHITE).size(ArmsUtils.dip2px(mContext,5))
                .build());
        List<String> datas=new ArrayList<>();
        datas.add("a");
        datas.add("b");
        datas.add("v");
        datas.add("d");
        datas.add("e");
        datas.add("a");
        recyclerView.setAdapter(new NewsAdapter(datas));
//        if (holder.itemView instanceof RecyclerView) {
//            recyclerView.setLayoutParams(new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
//
//        }

    }

    @Override
    public int getItemCount() {
        return 1;
    }
}
